package com.kotlin.lib.coroutines

import kotlinx.coroutines.*
import okio.buffer
import okio.source
import java.io.File
import kotlin.system.measureTimeMillis

fun main() = runBlocking<Unit> {
    val jobList = ArrayList<Deferred<String>>()
    val time = measureTimeMillis {
        File("E:\\download\\download").listFiles().filter {
            it.isFile
        }.forEach {
            val job = async(Dispatchers.Default) {
                it.source().buffer().readByteString().utf8()
//                it.readText()
            }
            jobList.add(job)
        }

        jobList.forEach {
            launch { val await = it.await() }
        }
    }


    println(time)
}